package com.zyh.supermark.system.controller;

import com.zyh.supermark.system.dao.impl.UserDaoImpl;
import com.zyh.supermark.system.domain.User;
import com.zyh.supermark.system.service.impl.UserServiceImpl;

import java.util.Random;
import java.util.Scanner;

public class UserController {
    public static final Scanner INPUT = new Scanner(System.in);

    public static void main(String[] args) {
        UserServiceImpl serviceImpl = new UserServiceImpl();
        while (true) {
            System.out.println("===========================欢迎使用超市用户管理系统==========================================");
            System.out.println("1.查询会员信息");
            System.out.println("2.删除会员信息");
            System.out.println("3.新增会员信息");
            System.out.println("4.退出系统");
            System.out.println("=========================================================================================");
            System.out.println("请输入您的选择：");
            int choice = INPUT.nextInt();
            switch (choice) {
                case 1://查询会员信息
                    serviceImpl.findAll();
                    break;
                case 2://删除会员信息
                    System.out.println("请输入您要删除的会员编号：");
                    int deleteId = INPUT.nextInt();
                    serviceImpl.delete(deleteId);
                    break;
                case 3://新增会员信息
                    System.out.println("请输入用户账号名：");
                    String newName = INPUT.next();
                    System.out.println("请选择卡类型：(黄金卡 铂金卡 钻石卡)：");
                    String newCardType = INPUT.next();
                    System.out.println("请输入会员积分：");
                    int newScore = INPUT.nextInt();
                    int newId = new Random().nextInt(9000) + 1000;
                    User user = new User(newId, newName, newCardType, newScore, "合法账户");
                    serviceImpl.add(user);
                    break;
                default:
                    System.out.println("系统退出！");
                    System.exit(0);
            }
        }
    }
}
